package com.titaniume.activitiweb;

import java.util.HashMap;
import java.util.Map;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/**
 *@program: activiti7_workflow
 *@description: UEL 表达式 流程启动  任务环节赋值
 *@author: renfei.huang
 *@create: 2021-11-11 10:16
 */
@SpringBootTest
public class Part6_UEL {

    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private TaskService taskService;


    //启动流程实例带产生，指定执行人
    @Test
    public void initProcessInstanceWithArgs() {
        //流程变量 ${ZhiXingRen} 可多个
        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("ZhiXingRen", "wukong");
        ProcessInstance processInstance = runtimeService
                .startProcessInstanceByKey(
                        "myProcess_UEL_V1",
                        "bkey002", variables);
        System.out.println("流程定义的ID: " + processInstance.getProcessDefinitionId());
    }

    //完成任务带参数 ,指定流程变量
    @Test
    public void completeTaskWithArgs() {
        //bajie 提交触发
        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("pay", "101");
        taskService.complete("81ace425-429e-11ec-92d6-8cec4b5c0c44",variables);
        System.out.println("完成任务");
    }

    //启动流程实例带参数，使用实体类
    @Test
    public void initProcessInstanceWithClassArgs() {

        UEL_POJO uel_pojo = new UEL_POJO();
        uel_pojo.setZhixinren("bajie");
        //流程变量
        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("uelpojo", uel_pojo);
        ProcessInstance processInstance = runtimeService
                .startProcessInstanceByKey(
                        "myProcess_UEL_V3",
                        "bkey002", variables);
        System.out.println("流程定义的ID: " + processInstance.getProcessDefinitionId());
    }


    //完成任务，指定多个候选人
    @Test
    public void initProcessInstanceWithCandiDateArgs() {

        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("houxuanren", "wukong,taseng");
        taskService.complete("06687777-42a1-11ec-a9e6-8cec4b5c0c44",variables);
        System.out.println("完成任务");
    }


    //直接指定流程变量
    @Test
    public void otherArgs() {
//        runtimeService.setVariable("06687777-42a1-11ec-a9e6-8cec4b5c0c44","pay","101");
//        runtimeService.setVariables();

    }


    //局部变量
    @Test
    public void otherLocalArgs() {
//        runtimeService.setVariableLocal();
//        runtimeService.setVariablesLocal();
    }
}
